package top.jiug.k_quartz;

import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;
import top.jiug.k_quartz.task.TestJob;

import java.text.SimpleDateFormat;
import java.util.Date;

public class App {

    public static void main(String[] args) {
        try {
            Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();

            // 创建任务
            JobDetail job = JobBuilder.newJob(TestJob.class).withIdentity("job1","group1").build();

            // 创建触发器（指定出发规则）
            CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity("trigger",
                    "group1").withSchedule(CronScheduleBuilder.cronSchedule("0 0/1 14 * * ?")).build();

            // 获取执行时间
            Date date = scheduler.scheduleJob(job,trigger);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
            System.out.println("已经安排任务：" + dateFormat.format(date));

            scheduler.start();

            System.out.println("结束");
        } catch (SchedulerException e) {
            System.out.println("错误");
            e.printStackTrace();
        }

    }

}
